package com.ruoyi.system.service.impl;

import com.ruoyi.system.entity.AlarmPerimeterRecord;
import com.ruoyi.system.mapper.AlarmPerimeterRecordMapper;
import com.ruoyi.system.service.AlarmPerimeterRecordService;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (AlarmPerimeterRecord)表服务实现类
 *
 * @since 2023-04-21 15:35:21
 */
@Service("alarmPerimeterRecordService")
public class AlarmPerimeterRecordServiceImpl implements AlarmPerimeterRecordService {
    @Resource
    private AlarmPerimeterRecordMapper alarmPerimeterRecordDao;

    @Resource
    private JdbcTemplate jdbcTemplate;

    /**
     * 通过ID查询单条数据
     *
     * @return 实例对象
     */
    @Override
    public AlarmPerimeterRecord queryById(String sn) {
        return this.alarmPerimeterRecordDao.queryById(sn);
    }

    @Override
    @SuppressWarnings("all")
    public Integer countAlarmPerimeterRecord(AlarmPerimeterRecord alarmPerimeterRecord) {
        String sql = "SELECT count(1) FROM alarm_perimeter_record";
        return jdbcTemplate.queryForObject(sql, Integer.class);
    }

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @Override
    @SuppressWarnings("all")
    public List<AlarmPerimeterRecord> queryByPage(AlarmPerimeterRecord alarmPerimeterRecord, int pageNum, int pageSize) {
        String sql = "SELECT * FROM alarm_perimeter_record limit " + pageNum + "," + pageSize;
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper(AlarmPerimeterRecord.class));
    }

    /**
     * 新增数据
     *
     * @param alarmPerimeterRecord 实例对象
     * @return 实例对象
     */
    @Override
    public AlarmPerimeterRecord insert(AlarmPerimeterRecord alarmPerimeterRecord) {
        this.alarmPerimeterRecordDao.insert(alarmPerimeterRecord);
        return alarmPerimeterRecord;
    }

    /**
     * 修改数据
     *
     * @param alarmPerimeterRecord 实例对象
     * @return 实例对象
     */
    @Override
    public AlarmPerimeterRecord update(AlarmPerimeterRecord alarmPerimeterRecord) {
        this.alarmPerimeterRecordDao.update(alarmPerimeterRecord);
        return this.queryById(alarmPerimeterRecord.getSn());
    }

    /**
     * 通过主键删除数据
     *
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String sn) {
        return this.alarmPerimeterRecordDao.deleteById(sn) > 0;
    }
}
